You are here: TI-Nspire™ Technology Program Editor eGuide > TI-Nspire™ Technology Program Editor Guide > Getting Started with the Program Editor > Defining a Program or Function

Defining a Program or Function

Starting a new Program Editor

1. Make sure you are in the document and problem in which you want to create the program or function.
2. Click Insert button on the application toolbar, and select Program Editor > New. (On the handheld, press ~ and select Insert > Program Editor > New.)

3. Type a name for the function or program you are defining.
4. Select the Type (Program or Function).
5. Set the Library Access:
- To use the function or program only from the current document and problem, select None.
- To make the function or program accessible from any document but not visible in the Catalog, select LibPriv.
- To make the function or program accessible from any document and also visible in the Catalog, select LibPub (Show in Catalog). For more information, see Libraries.
6. Click OK.

A new instance of the Program Editor opens, with a template matching the selections you made.

Entering Lines into a Function or Program

The Program Editor does not execute the commands or evaluate expressions as you type them. They are executed only when you evaluate the function or run the program.

1. If your function or program will require the user to supply arguments, type parameter names in the parentheses that follow the name. Separate parameters with a comma.

2. Between the Func and EndFunc (or Prgm and EndPrgm) lines, type the lines of statements that make up your function or program.

- You can either type the names of functions and commands or insert them from the Catalog.
- A line can be longer than the width of the screen; if so, you might have to scroll to view the entire statement.
- After typing each line, press Enter. This inserts a new blank line and lets you continue entering another line.
- Use the , , , and arrow keys to scroll through the function or program for entering or editing commands.

Inserting Comments

Comments can be useful to someone viewing or editing the program. They are not displayed when the program runs and have no effect on program flow. The © symbol displays at the beginning of the line with the comment.

Define LibPub volcyl(ht,r) =

Prgm

©volcyl(ht,r) => volume of cylinder  À

  Disp “Volume =”, approx(p ¦ r2 ¦ ht)

©This is another comment.

EndPrgm

À

Comment showing required syntax. Because this library object is public and this comment is the first line in a Func or Prgm block, the comment is displayed in the Catalog as help. For more information, see Libraries.

To insert a comment:

1. Position the cursor at the end of the line in which you want to insert a comment.
2. From the Actions menu, click Insert Comment, or press Ctrl+T.
3. Type the text of the comment after the © symbol.

Checking Syntax

The Program Editor lets you check the function or program for correct syntax.

From the Check Syntax & Store menu, click Check Syntax.

If the syntax checker finds any syntax errors, it displays an error message and tries to position the cursor near the first error so you can correct it.

Storing the Function or Program

You must store your function or program to make it accessible. The Program Editor automatically checks the syntax before storing.

An asterisk (*) is displayed in the upper left corner of the Program Editor to indicate that the function or program has not been stored.

From the Check Syntax & Store menu, click Check Syntax & Store.

If the syntax checker finds any syntax errors, it displays an error message and tries to position the cursor near the first error.

If no syntax errors are found, the message “Stored successfully“ is displayed in the status line at the top of the Program Editor.

Note: If the function or program is defined as a library object, you must also save the document in the designated library folder and refresh libraries to make the object accessible to other documents. For more information, see Libraries.